package com.goblin.model.uaa.repository;

import javax.persistence.EntityManager;

import com.goblin.common.response.PageHelper;
import com.goblin.common.response.Paged;
import com.goblin.model.base.BaseRepositoryImpl;
import com.goblin.model.uaa.po.QRole;
import com.goblin.model.uaa.po.Role;
import com.querydsl.core.QueryResults;
import com.querydsl.jpa.JPQLQuery;

public class RoleRepositoryImpl extends BaseRepositoryImpl<Role, Integer>
		implements RoleRepositoryCustom {

	public RoleRepositoryImpl(EntityManager entityManager) {
		super(Role.class, entityManager);
	}

	@Override
	public Paged<Role> paged(PageHelper pageable) {
		JPQLQuery<Role> query = this.jpaQueryFactory.selectFrom(QRole.role)
				.where(QRole.role.deleteTime.isNull()).orderBy(QRole.role.id.desc());
		query = (JPQLQuery<Role>) getQuerydsl(pageable, query);
		QueryResults<Role> results = query.fetchResults();
		return new Paged<Role>(results.getTotal(), results.getResults());
	}
}
